<template>
  <div class="mod-user">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()" class="data-form">
      <el-form-item>
        <el-input v-model="dataForm.keywords" placeholder="被邀账号、被邀用户" clearable style="width: 200px"></el-input>
      </el-form-item>
      <el-form-item>
        <el-select v-model="dataForm.gets" placeholder="类型" :value="dataForm.userType">
          <el-option key="1"  label="已领取" value="1"> </el-option>
          <el-option key="0"  label="未领取" value="0"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-date-picker
          value-format = "yyyy-MM-dd HH:mm:ss"
          v-model="dataForm.time"
          type="datetimerange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button icon="el-icon-download" type="primary" @click="excel()">导出</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        prop="recommTime"
        header-align="center"
        align="center"
        width="160"
        label="创建时间">
      </el-table-column>
      <el-table-column
        prop="passiveIphone"
        header-align="center"
        align="center"
        label="被邀账号">
      </el-table-column>
      <el-table-column
        prop="regTrueName"
        header-align="center"
        align="center"
        label="被邀用户">
      </el-table-column>
      <el-table-column
        prop="regUserType"
        header-align="center"
        align="center"
        label="被邀类型">
      </el-table-column>
      <el-table-column
        prop="userType"
        header-align="center"
        align="center"
        label="当前类型">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.userType == 1">区域运营商</el-tag>
          <el-tag v-else-if ="scope.row.userType == 2">普通联盟店</el-tag>
          <el-tag v-else-if ="scope.row.userType == 3">消费者</el-tag>
          <el-tag v-else-if ="scope.row.userType == 4">VIP会员</el-tag>
          <el-tag v-else-if ="scope.row.userType == 5">中级版联盟店</el-tag>
          <el-tag v-else-if ="scope.row.userType == 6">高级版联盟店</el-tag>
          <el-tag v-else-if ="scope.row.userType == 7">城市合伙人</el-tag>
          <el-tag v-else-if ="scope.row.userType == 8">城市合伙人联盟店</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="regIntegral"
        header-align="center"
        align="center"
        label="领取现金券">
      </el-table-column>
      <el-table-column
        prop="puserName"
        header-align="center"
        align="center"
        label="上级账号">
      </el-table-column>
      <el-table-column
        prop="ptrueName"
        header-align="center"
        align="center"
        label="上级名称">
      </el-table-column>
      <el-table-column
        prop="puserType"
        header-align="center"
        align="center"
        label="上级类型">
      </el-table-column>
      <el-table-column
        prop="getUserName"
        header-align="center"
        align="center"
        label="推荐账号">
      </el-table-column>
      <el-table-column
        prop="lastLoginDate"
        header-align="center"
        align="center"
        label="最后登录时间">
      </el-table-column>
      <!-- <el-table-column
        prop="getTrueName"
        header-align="center"
        align="center"
        label="推荐名称">
      </el-table-column>
      <el-table-column
        prop="getUserType"
        header-align="center"
        align="center"
        label="推荐类型">
      </el-table-column> -->
      <el-table-column
        prop="getIntegeral"
        header-align="center"
        align="center"
        label="推荐奖励金额">
      </el-table-column>
      <el-table-column
        prop="buyState"
        header-align="center"
        align="center"
        label="到账状态">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.buyState === '已绑定'" type="success">{{scope.row.buyState}}</el-tag>
          <el-tag v-if="scope.row.buyState === '未绑定'" type="danger">{{scope.row.buyState}}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.recommendId)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </div>
</template>

<script>
import AddOrUpdate from './consumer-update'
export default {
  data () {
    return {
      dataForm: {
        keywords: '',
        gets: '',
        time: new Date()
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: [],
      addOrUpdateVisible: false
    }
  },
  components: {
    AddOrUpdate
  },
  activated () {
    this.getDataList()
  },
  methods: {
      // 获取数据列表
    getDataList () {
      console.log(this.memberType)
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/member/consumer/queryConsumerList'),
        method: 'get',
        params: this.$http.adornParams({
          'page': this.pageIndex,
          'limit': this.pageSize,
          'keywords': this.dataForm.keywords,
          'gets': this.dataForm.gets,
          'lastStart': this.dataForm.time[0],
          'lastEnd': this.dataForm.time[1]
        })
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.dataList = data.data.list
          this.totalPage = data.data.totalCount
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
      // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
      // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    },
      // 多选
    selectionChangeHandle (val) {
      this.dataListSelections = val
    },
    // 新增 / 修改
    addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    },
    excel () {
      window.location.href = this.$http.adornUrl(`/member/consumer/exportInvitationRecordExcel?token=${this.$cookie.get('token')}&keywords=${this.dataForm.keywords}&startTime=${this.dataForm.time[0]}&endTime=${this.dataForm.time[1]}&buyState=${this.dataForm.gets}`)
    }
  }
}
</script>
<style>
  .characters{
    width:300px;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
  }
  .data-form .el-select{
    width: 110px;
  }
  .data-form .el-input{
    width: 110px;
  }
</style>
